<template>
  <div ref="mainCon" class="container">
    <topTitle
      v-if="!hiddleToolBar"
      :titleText="titleText"
      :titleExplain="titleExplain"
    ></topTitle>
    <div class="mainCon">
      <el-row class="toolbar searchInputWidth" style="padding-bottom: 0">
        <el-form :inline="true" :model="filterField" ref="info">
          <el-form-item label="企业" class="row-padding-bottom">
            <el-input
              placeholder="输入企业名称或统一社会信用代码"
              clearable
              v-model="filterField.companyName"
              @blur="filterField.companyName = changeValue($event)"
            ></el-input>
          </el-form-item>
          <el-form-item label="账号" class="row-padding-bottom">
            <el-input
              placeholder="输入账号"
              clearable
              v-model="filterField.userName"
              @blur="filterField.userName = changeValue($event)"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="icon iconfont iconchazhao1"
              @click="searchTable"
              class="searchBtn"
            >
              <span>搜索</span>
            </el-button>
          </el-form-item>
        </el-form>
      </el-row>
      <div class="spacing"></div>
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <el-table
          ref="tableBox1"
          :max-height="tableHeight"
          :data="tableList"
          v-loading="loading"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          stripe
          style="border: 1px solid #dfe6ec"
        >
          <el-table-column prop="companyName" label="企业名称" width="230">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.companyName"
                :columnName="'companyName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="uscc"
            label="统一社会信用代码"
            align="center"
            :formatter="formatTd"
            min-width="250"
          ></el-table-column>
          <el-table-column
            prop="boss"
            label="法人姓名"
            align="center"
            :formatter="formatTd"
            min-width="200"
          ></el-table-column>
          <el-table-column
            prop="bossTel"
            label="法人联系方式"
            align="center"
            :formatter="formatTd"
            min-width="200"
          ></el-table-column>
          <el-table-column
            prop="username"
            label="企业账号"
            align="center"
            :formatter="formatTd"
            min-width="200"
          ></el-table-column>
          <el-table-column label="操作" align="left" fixed="right" width="110">
            <template slot-scope="scope">
              <el-link
                type="primary"
                @click="goAdmin(scope.row)"
                v-hasBtn="'companyMaintain:detail'"
                >管理资料</el-link
              >
            </template>
          </el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关人员数据"></emptyTable>
          </div>
        </el-table>
        <!-- filterField为搜索条件 -->
        <!-- getTableList为获取子组件的数据 -->
        <Pagination
          ref="pagination"
          @getpageNo="getpageNo"
          @getpageSize="getpageSize"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
        ></Pagination>
      </div>
    </div>
  </div>
</template>

<script>
import scrollTable from '@/mixin/scrollTable.js'

export default {
  name: 'infoMaintain',
  mixins: [scrollTable],
  data() {
    return {
      titleText: '企业信息维护',
      titleExplain:
        '企业信息可由企业自主维护，也可由监管进行补充修改，当企业无法自助修改密保手机号时，监管可协助修改',
      //表格数据
      tableList: [],
      requestUrl: '/api-c/company/expand/compuserlist',
      //搜索条件
      filterField: {
        companyName: '',
        userName: '',
      },
      pageSize: 20,
      pageNo: 1,
      isShow: false, //列表加载
      loading: true,
    }
  },
  created() {
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData()
    })
  },
  activated() {
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData(this.pageNo, this.pageSize)
    })
  },
  methods: {
    getpageSize(val) {
      this.pageSize = val
    },
    getpageNo(val) {
      this.pageNo = val
    },
    getTableList(data) {
      this.tableList = data
      this.loading = false
      if (this.tableList.length < 1) {
        this.isShow = true
      }
    },
    searchTable() {
      this.pageSize = 20
      this.pageNo = 1
      this.$refs.pagination.getTableListData()
    },
    goAdmin(row) {
      this.$router.push({
        name: 'enterpriseDetail',
        path: 'home/enterpriseSet/enterpriseDetail',
        query: {
          companyId: row.companyId,
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/enterpriseBasicInfo/infoMaintain',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
  },
}
</script>

<style lang="less" scoped>
.mainCon {
  top: 213px;
}
@import '../../../static/css/filterArea.less';
</style>
